
<div class="header-panel">
    <span id="titleDiv" style="float: left">新增内部服务</span><a id="returnClick" href="javascript:;" style="float: right">返回></a>
</div>
<script type="text/javascript">
    $("#returnClick").on("click",function(){
       var url = "./pages/serviceManage/inner/list.html";
       $("#digitalChinaCurrentUrl").val(url);
        $("#tab-content-body").load(url);
    });
</script>
<div class="container-fluid container-full">
    <form class="form-horizontal" id="dismissEventForm">
        <div class="row-fluid form-group first-form-group">
            <label class="col-sm-2 control-label"><span class="required">*</span>数据源：</label>
            <div class="col-sm-4">
                <select id="dataSource" class="form-control input-sm">
                    <option value="1">数据源1</option>
                    <option value="2">数据源2</option>
                    <option value="3">数据源3</option>
                </select>
            </div>
        </div>
        <div class="row-fluid form-group">
            <div class="row">
                <label class="col-sm-2 control-label"><span class="required">*</span>服务目录：</label>
                <div class="col-sm-4">
                    <select id="serverMenu" class="form-control input-sm">
                        <option value="1">目录1</option>
                        <option value="2">目录2</option>
                        <option value="3">目录3</option>
                    </select>
                </div>
                <label class="col-sm-2 control-label "><span class="required">*</span>服务代码：</label>
                <div class="col-sm-4">
                    <input id="serviceCode" class="form-control input-sm validate[required,maxSize[20],custom[onlyLetterSp]]">
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label"><span class="required">*</span>请求方式：</label>
                <div class="col-sm-4">
                    <label class="checkbox-inline"> <input class="validate[required] checkbox" type="checkbox" name="requestMethod" id="ckPOST" value="post"> POST
                    </label> <label class="checkbox-inline"> <input class="validate[required] checkbox" type="checkbox" name="requestMethod" id="ckGET" value="get"> GET
                    </label>
                </div>

                <label class="col-sm-2 control-label"><span class="required">*</span>返回格式：</label>
                <div class="col-sm-4">
                    <label class="checkbox-inline"> <input class="validate[required] checkbox" type="checkbox" name="resultFormat" checked="checked" id="ckJSON" value="json"> JSON
                    </label> <label class="checkbox-inline"  style="display:none" > <input class="validate[required] checkbox" type="checkbox" name="resultFormat" id="ckJXML" value="xml"> XML
                    </label>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label"><span class="required">*</span>服务名称：</label>
                <div class="col-sm-10">
                    <input class="form-control input-sm validate[required,maxSize[30]]"  id="serviceName">
                </div>

            </div>

            <div class="row">
                <label class="col-sm-2 control-label"><span class="required">*</span>描 述：</label>
                <div class="col-sm-10">
                    <textarea id="configRemark" class="form-control validate[required,maxSize[150]]" rows="3" style="resize: none;"></textarea>
                </div>
            </div>
            <div class="row">
                <button id="toggleConfigPanel" class="toggle-panel" type="button" >
                    辅助配置 <span style="float: right" class="glyphicon glyphicon-chevron-down"></span> <span style="float: right" class="glyphicon glyphicon-chevron-up hide"></span>
                </button>
            </div>
        </div>
        <div id="argdismissEventForm" class="row-fluid form-group first-form-group">
            <div class="row">
                <label class="col-sm-2 control-label"><span class="required">*</span>数据表名：</label>
                <div class="col-sm-10">
                    <!--<select id="datatableName" class="form-control input-sm">
                        <option value=""></option>
                        <option value="table1">表1</option>
                        <option value="table2">表</option>
                        <option value="table3">表2</option>
                    </select>-->
                    <div id="autoCompleteSelect"><input id="datatableName" class="form-control input-sm"/><img id="autoCompleteBtn" src="theme/images/icon/arrow-down-black.png" style="position: relative;left: 58.3em;cursor: pointer;top:-1.9em;"></div>
                </div>
            </div>
            <div class="row">
            <label class="col-sm-2 control-label">请求参数配置：</label>
            <div class="col-sm-10">
                <div>
                    <button class="add-row-btn" type="button" id="addRequestBtn1">
                        <span>+</span>新建
                    </button>
                </div>
                <table id="config-request-param1" class="table table-striped table-hover table-bordered my-table" cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th>字段</th>
                        <th>字段描述</th>
                        <th>参数名称</th>
                        <th width="8%">必填</th>
                        <th width="12%">运算规则</th>
                        <th>参数描述</th>
                        <th class="delete-row">删除</th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
            <div class="row">
                <label class="col-sm-2 control-label">区间参数配置：</label>
                <div class="col-sm-10">
                    <!--<div ><button class="btn-green add-row-btn">新建</button></div>-->
                    <div>
                        <button class="add-row-btn" type="button" id="addIntervelBtn1">
                            <span>+</span>新建
                        </button>
                    </div>
                    <table id="config-interval-param1" class="table table-striped table-hover table-bordered my-table" cellspacing="0" style="width: 50% !important;">
                        <thead>
                            <tr>
                                <th>字段</th>
                                <th>区间</th>
                                <th width="20%">删除</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <div class="row">
                <label class="col-sm-2 control-label">返回参数配置：</label>
                <div class="col-sm-10">
                    <div>
                        <button class="add-row-btn" type="button" id="addReturnBtn1">
                            <span>+</span>新建
                        </button>
                    </div>
                    <table id="config-return-param1" class="table table-striped table-hover table-bordered my-table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>名称</th>
                                <th>JSON别名</th>
                                <th>参数描述</th>
                                <th width="8%">排序</th>
                                <th class="delete-row">删除</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="row btn-medium-blue-container">
                <button id="generoyBtn" class="btn-medium-blue" type="button">生&nbsp;&nbsp;&nbsp;成</button>
            </div>
        </div>

        <div class="row-fluid form-group first-form-group">
            <div class="row">
                <label class="col-sm-2 control-label">请求参数配置：</label>
                <div class="col-sm-10">
                    <div>
                        <button class="add-row-btn" type="button" id="addRequestBtn2">
                            <span>+</span>新建
                        </button>
                    </div>
                    <table id="config-request-param2" class="table table-striped table-hover table-bordered my-table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th width="20%">名称</th>
                                <th  width="30%">类型</th>
                                <th width="8%">必填</th>
                                <th  width="32%">描述</th>
                                <th class="delete-row">删除</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label">SQL片段配置：</label>
                <div class="col-sm-10">
                    <!--<div ><button class="btn-green add-row-btn">新建</button></div>-->
                    <div>
                        <button class="add-row-btn" type="button" id="addIntervelBtn2">
                            <span>+</span>新建
                        </button>
                    </div>
                    <table id="config-interval-param2" class="table table-striped table-hover table-bordered my-table" cellspacing="0" style="width: 100% !important;">
                        <thead>
                            <tr>
                                <th width="20%">SQL片段名称</th>
                                <th width="20%">参数名称</th>
                                <th>实际SQL</th>
                                <th width="7%">删除</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <div class="row">
                <label class="col-sm-2 control-label">返回参数配置：</label>
                <div class="col-sm-10">
                    <div>
                        <button class="add-row-btn" type="button" id="addReturnBtn2">
                            <span>+</span>新建
                        </button>
                    </div>
                    <table id="config-return-param2" class="table table-striped table-hover table-bordered my-table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th width="20%">名称</th>
                                <th width="30%">类型</th>
                                <th width="40%">描述</th>
                                <th class="delete-row">删除</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="row">
                <label class="col-sm-2 control-label">输入SQL语句：</label>
                <div class="col-sm-10">
                    <textarea id="querySql" class="form-control validate[required]" rows="3" style="resize: none;"></textarea>
                </div>
            </div>
            <div id="inner_update_log_row" class="row" >
                <label class="col-sm-2 control-label">更新日志：</label>
                <div class="col-sm-10">
                    <textarea style="width: 100%;" class="validate[required]" rows="5" id="editRemark" name="editRemark" placeholder="请填写本次更新内容"></textarea>
                </div>
            </div>
            <div class="row btn-medium-blue-container">
                <button id="saveBtn" class="btn-medium-blue" type="button">保&nbsp;&nbsp;&nbsp;存</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
	$('#saveBtn')
			.on(
					'click',
					function() {
					 // 验证表达，成功才执行ajax请求
						if (!$("#dismissEventForm").validationEngine("validate")) {
							return;
						}

					    
						var postArgs = {};
						postArgs.parentId = $("#serverMenu").val();
						postArgs.dataSourceId = $("#dataSource").val();
						postArgs.serviceName = $("#serviceName").val();
						postArgs.serviceCode = $("#serviceCode").val();
						//接口类型（3:空间数据，2::外部接口，1:配置接口）
						postArgs.serviceType = 1;
						postArgs.configRemark = $("#configRemark").val();
						postArgs.requestMethod = "";
						$("input[name=requestMethod]").each(function() {
							if ($(this).attr("checked")) {
								postArgs.requestMethod += "," + $(this).val();
							}
						});
						if (!postArgs.requestMethod
								|| postArgs.requestMethod.length <= 0) {
							alert("选择请求方式");
							return;
						} else {
							postArgs.requestMethod = postArgs.requestMethod
									.substring(1);
						}

						postArgs.resultFormat = "";
						$("input[name=resultFormat]").each(function() {
							if ($(this).attr("checked")) {
								postArgs.resultFormat += "," + $(this).val();
							}
						});
						if (!postArgs.resultFormat
								|| postArgs.resultFormat.length <= 0) {
							alert("选择返回格式");
							return;
						} else {
							postArgs.resultFormat = postArgs.resultFormat
									.substring(1);
						}
						postArgs.datatableName = $("#datatableName").val();
						postArgs.querySql = $("#querySql").val();
						postArgs.inputArgsJson = JSON.stringify(Table
								.getTableValues("config-request-param2"));
						postArgs.sqlSegmentJson = JSON.stringify(Table
								.getTableValues("config-interval-param2"));
						var outArgs = Table .getTableValues("config-return-param2");
						postArgs.outputArgsJson = JSON.stringify(outArgs);

						postArgs.navInputParamJson = JSON.stringify(Table
								.getTableValues("config-request-param1"));
						var dates = Table .getTableValues("config-interval-param1");
						postArgs.navDateRangeJson = JSON.stringify(dates);
						
						postArgs.navOutputParamJson = JSON.stringify(Table
								.getTableValues("config-return-param1"));
						postArgs.editMark = "初次添加服务";
						if(hasConfigId){
						    postArgs.editMark =$("#editRemark").val();
						}
						//验证时间区间 必须填写
						
					 	for(var i=0;i<dates.length;i++){ 
						    if(!(dates[i].dataRange&&dates[i].dataRange>0)){
						        alert("请输入正确的时间区间！！");
						        return;
						    }
						}
					 	//验证输出参数
					 	if(outArgs.length<=0){
					 	   alert("输出参数个数不能为0！");
					        return;
					 	}
					 	
						postConfigerSave(postArgs, hasConfigId);
						//alert(JSON.stringify(postArgs)); 
					});
	var selectedTableFields = "<option>f1</option><option>f2</option><option>f3</option>";
	var selectedTableFieldsDateType="";
	var selectedTableFieldsDesc = {};
	var selectedTableFieldsType = {};
	var generalSQL="";
	
	var hasConfigId = getQueryString("configId");
	if(hasConfigId){
	    $("#titleDiv").text("修改内部服务");
	}else{
	    $("#titleDiv").text("新增内部服务");
	}
	var readOnly = getQueryString("readOnly");
	if(readOnly){
	    $("#saveBtn").css("display","none"); 
	    $("#titleDiv").text("内部服务");
	}
</script>
<script src="pages/dataBaseManage/js/addService.js"></script>
<script src="pages/dataBaseManage/js/js.js"></script>

